//
// Created by 215609 on 2024/8/17.
//

#ifndef TSAVPLAYER_HWCODERPLAYER_H
#define TSAVPLAYER_HWCODERPLAYER_H
#include "BasePlayer.h"
#include "memory"
#include "LogUtil.h"
#include "AVPacketQueue.h"
#include <android/native_window.h>
#include <android/native_window_jni.h>
#include <media/NdkMediaCodec.h>
#include <media/NdkMediaExtractor.h>
#define MAX_PATH   2048
class HWCoderPlayer:public BasePlayer {
public:
      HWCoderPlayer(){};
      ~HWCoderPlayer(){};
      void Play() override;

    int InitDecoder();
      virtual void init(JNIEnv *jniEnv, jobject obj, char *url, int renderType, jobject surface);
       static void DeMuxThreadProc(HWCoderPlayer* player);
    JNIEnv * GetJNIEnv(bool *isAttach) override
private:
    char m_Url[MAX_PATH] = {0};
    ANativeWindow*       m_ANativeWindow = nullptr;

    AVPacketQueue*    m_VideoPacketQueue = nullptr;
    AVPacketQueue*    m_AudioPacketQueue = nullptr;
    thread*              m_DeMuxThread   = nullptr;

    AVFormatContext*   m_AVFormatContext = nullptr;


    AVCodecContext*      m_AudioCodecCtx = nullptr;
    AVCodecContext*      m_VideoCodecCtx = nullptr;

    AVRational          m_FrameRate;
    AVBitStreamFilterContext*     m_Bsfc = nullptr;
    int                 m_VideoStreamIdx = -1;
    int                 m_AudioStreamIdx = -1;

   AMediaExtractor*    m_MediaExtractor = nullptr;

    JavaVM *m_JavaVM = nullptr;
    jobject m_JavaObj = nullptr;
};


#endif //TSAVPLAYER_HWCODERPLAYER_H
